



import pymysql
#封装建立连接的对象
def get_conn():
    conn = pymysql.connect(
        host="litemall.hogwarts.ceshiren.com",
        port=13306,
        user="test",
        password="test123456",
        database="litemall",
        charset="utf8mb4"
    )
    return conn
#执行sql语句
def execute_sql(sql):
    connect=get_conn()
    cursor=connect.cursor()
    cursor.execute(sql)#执行sql
    record=cursor.fetchone()#查询记录
    return  record
#查询user123这个用户的购物车有一个为hogwarts1的商品
sql_res=execute_sql("select * from litemall_cart where "
            "user_id=1 and deleted=0 and "
            "goods_name='hogwarts1'")
assert sql_res
sql_res = execute_sql()

